/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 * Created on Jan 22, 2007
 */
package cesynch.crystal.synchronizer;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * <p>Object representing a person.</p>
 * 
 * @author <a href="mailto:cesynch@gmail.com">cesynch</a>
 */
public class Person
{
    /** String for uid value */
    private String uid;
    /** String for common name */
    private String cn;
    /** String for surname */
    private String sn;
    /** String for givenName */
    private String givenName;
    /** String for userPassword */
    private String userPassword; 
    /** Set of Crystal group ids */
    private Set ceGroupIds = new HashSet();

    /**
     * <p>Default constructor.</p>
     */
    public Person()
    {
        super();
    }
    
    /**
     * <p>Constructor taking uid string.</p>
     * 
     * @param uid value of the uid.
     */
    public Person(String uid)
    {
        super();
        setUid(uid);
    }

    /**
     * <p>Returns the unique id.</p>
     * 
     * @return Returns the uid.
     */
    public String getUid()
    {
        return uid;
    }
    
    /**
     * <p>Sets the unique id value.</p>
     * 
     * @param uid The uid to set.
     */
    public void setUid(String uid)
    {
        this.uid = uid;
    }
    
    /**
     * <p>Returns the common name attribute.</p>
     * 
     * @return Returns the cn.
     */
    public String getCn()
    {
        return cn;
    }
    
    /**
     * <p>Sets the common name attribute.</p>
     * 
     * @param cn The cn to set.
     */
    public void setCn(String cn)
    {
        this.cn = cn;
    }
    
    /**
     * <p>Returns the surname attribute.</p>
     * 
     * @return Returns the sn.
     */
    public String getSn()
    {
        return sn;
    }
    
    /**
     * <p>Sets the surname attribute.</p>
     * 
     * @param sn The sn to set.
     */
    public void setSn(String sn)
    {
        this.sn = sn;
    }
    
    /**
     * <p>Returns the givenName attribute.</p>
     * 
     * @return Returns the givenName.
     */
    public String getGivenName()
    {
        return givenName;
    }
    
    /**
     * <p>Sets the givenName</p>
     * 
     * @param givenName The givenName to set.
     */
    public void setGivenName(String givenName)
    {
        this.givenName = givenName;
    }
    
    /**
     * <p>Returns the user password attribute.</p>
     * 
     * @return Returns the userPassword.
     */
    public String getUserPassword()
    {
        return userPassword;
    }
    
    /**
     * <p>Sets the user password attribute.</p>
     * 
     * @param userPassword The userPassword to set.
     */
    public void setUserPassword(String userPassword)
    {
        this.userPassword = userPassword;
    }
    
    /**
     * <p>Resets all values so the object can be used again.</p>
     */
    public void reset()
    {
        this.uid = null;
        this.cn = null;
        this.sn = null;
        this.givenName = null;
        this.userPassword = null;
    }
    
    
    /**
     * @see java.lang.Object#toString()
     */
    public String toString()
    {
        return "Person: uid=" + getUid() + " cn=" + getCn() + " sn=" + getSn() 
                + " giveName=" + getGivenName() + " userPassword=" + getUserPassword();
                
    }
    
    /**
     * @see java.lang.Object#equals(java.lang.Object)
     */
    public boolean equals(Object obj)
    {
        if (null == obj || !(obj instanceof Person))
        {
            return false;
        }
        Person comp = (Person) obj;
        if (comp.getUid() == null )
        {
            if (getUid() == null)
            {
                return true;    
            }
            else
            {
                return false;    
            }
        }
        return comp.getUid().equalsIgnoreCase(getUid());
    }
    
    /**
     * @see java.lang.Object#hashCode()
     */
    public int hashCode()
    {
        if (getUid() == null)
        {
            return 17;
        }
        return getUid().toLowerCase().hashCode();
    }

    public boolean addCEGroupId(Object o)
    {
        return ceGroupIds.add(o);
    }

    public Iterator ceGroupIdIterator()
    {
        return ceGroupIds.iterator();
    }

    public boolean removeCEGroupId(Object o)
    {
        return ceGroupIds.remove(o);
    }
}
